package com.loyal.loyalerp.humenresource.category.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loyal.loyalerp.humenresource.category.entity.Gy_ConfigType;
import com.loyal.loyalerp.humenresource.category.service.ConfigTypeReadService;
import com.loyal.loyalerp.humenresource.category.service.ConfigTypeWriteService;

@Controller
@RequestMapping("/categoryType")
public class CategoryApi {
	
	@Autowired
	private ConfigTypeReadService readService;
	
	@Autowired
	private ConfigTypeWriteService writeService;
	
	@RequestMapping("/jsp")
	public String catttt() {
		return "HumenResource/BaseSetting/category";
	}
	
	@RequestMapping("/editjsp")
	public String editjsp() {
		return "HumenResource/BaseSetting/editCategory";
	}
	
	@ResponseBody
	@RequestMapping("/list")
	public List<Gy_ConfigType> getAllConfigType(){
		return readService.retrieveAllConfigType();
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public String deleteConfigType(int id) {
		System.out.println("----------------"+id);
		writeService.deleteConfigType(id);
		return "success";
	}
	
	@ResponseBody
	@RequestMapping("/add")
	public Map<String,Object> addConfigType(String type){
		Map<String,Object> map=new HashMap<String, Object>();
		System.out.println("----------"+type);
		Gy_ConfigType con=new Gy_ConfigType(type);
		int r=writeService.addConfigType(con);
		if(r==1) {
			map.put("status", 200);
		}
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/edit")
	public Map<String,Object> editConfigType(int id,String type){
		Map<String,Object> map=new HashMap<String, Object>();
		System.out.println(id+"----------"+type);
		Gy_ConfigType con=new Gy_ConfigType(id,type);
		String msg=writeService.editConfigType(con);
		if("success".equals(msg)) {
			map.put("status", 200);
		}
		map.put("msg", msg);
		return map;
	}
	
}
